<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016-8-3
 * Time: 16:58
 */

namespace App\Repositories;



use App\Models\OperationRecord;

class OperationRecordRepository extends BaseRepository{

    public function __construct(OperationRecord $operationRecord)
    {
        $this->model = $operationRecord;
    }

    /**
     * 资源列表
     * @param array $data
     * @param string $extra
     * @param int $size
     */
    public function index($data, $extra = '', $size = 10)
    {

    }

    /**
     * 添加
     * @param array $inputs
     * @param string $extra
     * @return mixed
     */
    public function store($inputs = [], $extra = '')
    {
        $model = new $this->model;
        return $this->save($model,$inputs);
    }


    /**
     * 删除
     * @param int $id
     * @param string $extra
     * @return int
     */
    public function destroy($id, $extra = '')
    {
        $list = $this->getById($id);
        return $list->delete();
    }

    /**
     * 修改
     * @param int $id
     * @param array|string $extra
     */
    public function edit($id,$extra)
    {
        // TODO: Implement edit() method.
    }

    /**
     * 修改
     * @param int $id
     * @param array $inputs
     * @param string $extra
     * @return mixed
     */
    public function update($id, $inputs, $extra = '')
    {
        $model = $this->getById($id);
        return $this->save($model,$inputs);
    }


    /**
     * @param $model
     * @param $inputs
     * @return mixed
     */
    public function save($model, $inputs)
    {
        if (array_key_exists('type',$inputs)) {
            $model->type = e($inputs['type']);//操作类型 1：学时预约  2：取消预约
        }
        if (array_key_exists('school_id',$inputs)) {
            $model->school_id = e($inputs['school_id']);//驾校id
        }
        if (array_key_exists('coach_id',$inputs)) {
            $model->coach_id = e($inputs['coach_id']);//教练id
        }
        if (array_key_exists('putime_id',$inputs)) {
            $model->putime_id = e($inputs['putime_id']);//学时id
        }
        if (array_key_exists('put_startime',$inputs)) {
            $model->put_startime = e($inputs['put_startime']);//学时开始时间
        }
        if (array_key_exists('put_endtime',$inputs)) {
            $model->put_endtime = e($inputs['put_endtime']);//学时结束时间
        }
        if (array_key_exists('money',$inputs)) {
            $model->money = e($inputs['money']);//学时费用
        }
        if (array_key_exists('student_id',$inputs)) {
            $model->student_id = e($inputs['student_id']);//预约学员id
        }
        if (array_key_exists('operation_id',$inputs)) {
            $model->operation_id = e($inputs['operation_id']);//操作着id
        }
        if (array_key_exists('operationtime',$inputs)) {
            $model->operationtime = e($inputs['operationtime']);//操作时间
        }
        if (array_key_exists('study_time',$inputs)) {
            $model->study_time = e($inputs['study_time']);//学时
        }
        $model->save();
        return $model;

    }





}